package com.hnucm.c202001020214;

import androidx.annotation.NonNull;

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.gyf.immersionbar.ImmersionBar;
import com.hnucm.c202001020214.fragment.Bazaar;
import com.hnucm.c202001020214.fragment.Sale;
import com.hnucm.c202001020214.fragment.UserCenter;
import com.hnucm.c202001020214.fragment.Warehouse;

public class MainActivity extends BaseActivity {

    Warehouse warehouse = new Warehouse();
    Bazaar bazaar = new Bazaar();
    Sale sale = new Sale();
    UserCenter userCenter = new UserCenter();



    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()){

                //首页
                case R.id.item_bottom_warehouse:
                    getSupportFragmentManager().beginTransaction().show(warehouse).hide(bazaar).hide(sale).hide(userCenter).commit();
                    return true;

                //
//                case R.id.item_bottom_bazaar:
//                    getSupportFragmentManager().beginTransaction().show(bazaar).hide(warehouse).hide(sale).hide(userCenter).commit();
//                    return true;

                //出售
                case R.id.item_bottom_sale:
                    getSupportFragmentManager().beginTransaction().show(sale).hide(warehouse).hide(bazaar).hide(userCenter).commit();
                    return true;

                //我的
                case R.id.item_bottom_user_center:
                    getSupportFragmentManager().beginTransaction().show(userCenter).hide(warehouse).hide(bazaar).hide(sale).commit();
                    return true;
            }


            return false;
        }
    };



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        ImmersionBar.with(this)
                // .statusBarColor(R.color.touming)
                .init();

        BottomNavigationView navigation = findViewById(R.id.bottomNavigationView_main);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        getSupportFragmentManager().beginTransaction().show(warehouse).hide(bazaar).hide(sale).hide(userCenter).commit();
        getSupportFragmentManager().beginTransaction().show(warehouse).hide(bazaar).hide(sale).hide(userCenter).commit();

        getSupportFragmentManager().beginTransaction().add(R.id.fragment,warehouse).commit();
        //getSupportFragmentManager().beginTransaction().add(R.id.fragment,bazaar).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment,sale).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment,userCenter).commit();





    }
}